package interfaz;

import org.uqbar.arena.actions.MessageSend;




import org.uqbar.arena.layout.VerticalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;import org.uqbar.arena.widgets.TextFilter;
import org.uqbar.arena.widgets.TextInputEvent;
import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.windows.MainWindow;
import org.uqbar.arena.windows.SimpleWindow;
import org.uqbar.arena.windows.WindowOwner;

import adapter.MesaAdapter;

import Ruleta.Mesa;

public class UnirPersonaAMesaWindow extends SimpleWindow<MesaAdapter> {

	
	public UnirPersonaAMesaWindow(WindowOwner parent, MesaAdapter model) {
		super(parent, model);
	}

	public final String UNIRSE="unirse";
	
	@Override
	protected void addActions(Panel actionsPanel) {
		
		Button unirse = new Button(actionsPanel);
		unirse.setCaption("Unirse!");
		unirse.onClick(new MessageSend(this,this.UNIRSE));
		
	}

	@Override
	protected void createFormPanel(Panel mainPanel) {
		mainPanel.setLayout(new VerticalLayout());
		
		this.setTitle("Ruleta");
		
		Label bienvenida = new Label(mainPanel);
		bienvenida.setText("Bienvenido a la mesa, ingrese sus datos para unirse" + "\n" );
		
		Label name = new Label(mainPanel);
		name.setText("nombre:");
		TextBox nombre = new TextBox(mainPanel);
		nombre.withFilter(new TextFilter(){

			public boolean accept(TextInputEvent event) {	
				return event.getPotentialTextResult().matches("[a-zA-Z]*");
				
			}
		});
		nombre.bindValueToProperty(MesaAdapter.NOMBRE);
		
		Label money = new Label(mainPanel);
		money.setText("dinero:");
		TextBox dinero = new TextBox(mainPanel);
		dinero.withFilter(new TextFilter(){

			public boolean accept(TextInputEvent event) {
				return event.getPotentialTextResult().matches("[0-9]*");
			}
		});
		dinero.bindValueToProperty(MesaAdapter.DINERO);	
	}
	
	public void unirse(){
		
		this.getModel().unirse();
		this.close();
		
	}

}